<template>
	<view class="editNickname">
		<title :center="false" @titleHeight='setPaddingTop' title="昵称" icon="icon" iconSize="38" color="#000000"
		bgcolor="#ffffff" :bold="false" @toclick="toBack()"></title>
		<view class="content" :style="{'margin-top':contentMarginTop + 'px','height':`calc(100vh - ${contentMarginTop}px)`}">
			<view class="nickname">
				<view class="title">
					昵称
				</view>
				<u-input v-model="value" type="text" :border="border" :placeholder="placeholder" :clearable="false" />
				<view v-show="value.length > 0">
					<view class="close" @tap="value = ''">
						<u-icon name="close-circle-fill" color="#666" size="32"></u-icon>
					</view>
				</view>
			</view>
			<view class="button" @tap="amendUserInfo({nickName:value})">
				确定修改
			</view>
		</view>
	</view>
</template>

<script>
	import title from '@/pages/components/title.vue'
	export default {
		data(){
			return {
				contentMarginTop:93,
				value:'',
				placeholder: '',
			}
		},
		components:{
			title,
		},
		onShow() {
			this.placeholder = this.$store.state.uInfo.name || (uni.getStorageInfoSync('uInfo')&&JSON.parse(uni.getStorageInfoSync('uInfo')).name)
		},
		methods:{
			setPaddingTop(data){
				// console.log(data);
				this.contentMarginTop = data.height
			},
			toBack(){
				this.$common.toBack(1)
			},
			// 更新资料
			amendUserInfo(data = {}) {
				this.$api.updateUserInfo({
					userinfo: JSON.stringify(data)
				}).then(res => {
					// console.log('res',res);
					this.$store.commit('setUserInfo', res.data.data)
					uni.setStorageSync('uInfo', JSON.stringify(this.$store.state.uInfo))
					this.toBack(1)
				
				})
			},
		}
	}
</script>

<style lang="less" scoped>
	.editNickname {
		height: 100%;
		width: 100%;
		.content {
			background-color: #F4F4F4;
			padding: 20rpx;
			
			.nickname {
				background: #FFFFFF;
				border-radius: 12rpx;
				display: flex;
				justify-content: flex-start;
				align-items: center;
				padding: 18rpx 0 18rpx 32rpx;
				position: relative;
				.title {
					font-size: 32rpx;
					font-family: PingFang SC-Regular, PingFang SC;
					font-weight: 400;
					color: #000000;
					margin-right: 20rpx;
				}
				/deep/.u-input__input{
					caret-color: #165DFF;
					&::placeholder {
						color: #999999;
						
					}
					
				}
				/deep/.u-input__right-icon {
					display: flex;
					align-items: center;
					justify-content: center;
				} 
				.close {
					height: 70rpx;
					width: 70rpx;
					display: flex;
					align-items: center;
					justify-content: center;
					position: absolute;
					top: 50%;
					right: 40rpx;
					transform: translateY(-50%);
				}
			}
			.button {
				padding: 30rpx 0;
				display: flex;
				justify-content: center;
				border-radius: 100rpx;
				background: linear-gradient(90deg, #FF5588 0%, #EF424F 100%);
				margin-top: 20rpx;
				
				font-size: 32rpx;
				font-family: PingFang SC-Medium, PingFang SC;
				font-weight: 500;
				color: #FFFFFF;
				line-height: 36rpx;
			}
		}
	}
</style>